layui.use(['layer', 'form', 'table', 'admin', 'ax', 'func','laydate'], function () {
    var $ = layui.$;
    var layer = layui.layer;
    var form = layui.form;
    var table = layui.table;
    var $ax = layui.ax;
    var admin = layui.admin;
    var func = layui.func;
    var laydate=layui.laydate;


    //渲染时间选择框
    laydate.render({
        elem: '#timeLimit',
        range: true,
        trigger: 'click',
        // max: Feng.currentDate()
    });
    /**
     * 系统管理--消息管理
     */
    var Notice = {
        tableId: "noticeTable"    //表格id
    };
    $("#condition").on("input",function(e){
        //获取input输入的值
        Notice.search();
    });
    form.on('select(dm)', function(data){
        Notice.search();
    });
    /**
     * 选中行效果
     */
    table.on('row(noticeTable)',function(obj){
        $(obj.tr).siblings().css("background-color","");
        obj.tr.css({"background-color":"#dadad9"});
    });
    /**
     * 检索店名
     */
    var languageAjax = new $ax(Feng.ctxPath + "/btyXd/getDm");
    var languageResult = languageAjax.start();
    $.each(languageResult, function( index, val ) {
        $("#dm").append("<option value='"+val.dm+"'>"+val.dm+"</option>");
    } );
    form.render('select');
    /**
     * 初始化表格的列
     */
    Notice.initColumn = function () {
        return [[
            {type: 'checkbox',LAY_CHECKED:true,hide:true},
            {field: 'id', align: "center", hide: true, sort: true, title: 'id'},
            // {align: 'center', type: "numbers", title: '序号'},
            {field: 'dm', align: "center", sort: true, title: '店名',width:100,fixed: 'left'},
            {field: 'ctbh', align: "center", sort: false, title: '餐厅编号',width:110},
            {field: 'zf', align: "center", sort: true, title: '总分',width:80},
            {align: 'center', toolbar: '#tableBar', title: '操作', minWidth: 150},
            // {field: 'wwztImg', align: "center", sort: false, title: '图片',templet: function (d) {
            //         if (d.wwztImg === undefined || d.wwztImg === "") {
            //             return "<p>暂无</p>";
            //         } else {
            //             return "<img src='"+ d.wwztImg + "' style='height: 100%; max-width: 100%;' >" ;
            //             //return '<div class="show_img"><img  src="'+d.picture+'" alt="" width="100px" height="100px"></div>';
            //         }
            //     }},
            {field: 'dz', align: "center", sort: false, title: '店长',width:80},
            {field: 'xdrq', align: "center", sort: true, title: '巡店日期',width:110},
            {field: 'xdr', align: "center", sort: false, title: '巡店人',width:80},
            {field: 'wwzt', align: "center", sort: false, title: '外围是否干净',width:120},
            {field: 'qtdmzt', align: "center", sort: false, title: '前厅地面是否干净',width:150},
            {field: 'tszt', align: "center", sort: false, title: '通风状态',width:90},
            {field: 'dgzt', align: "center", sort: false, title: '灯光状态',width:90},
            {field: 'zswzt', align: "center", sort: false, title: '装饰物是否干净',width:130},
            {field: 'btwpzt', align: "center", sort: false, title: '吧台是否整齐',width:120},
            {field: 'qtzt', align: "center", sort: false, title: '前厅地脚线是否干净',width:160},
            {field: 'zztzt', align: "center", sort: false, title: '自助台是否整齐',width:130},
            {field: 'cjzt', align: "center", sort: false, title: '餐具是否整齐',width:120},
            {field: 'xsjzt', align: "center", sort: false, title: '洗手间是否干净',width:130},
            {field: 'ctybzt', align: "center", sort: false, title: '店员仪表是否标准',width:150},
            {field: 'ctzjzt', align: "center", sort: false, title: '店员指甲状态',width:120},
            {field: 'xm', align: "center", sort: false, title: '姓名',width:70},
            {field: 'fwkmzt', align: "center", sort: false, title: '服务口码是否完整',width:150},
            {field: 'fwgczt', align: "center", sort: false, title: '服务状态',width:100},
            {field: 'dpzb', align: "center", sort: true, title: '大众点评流水占比',width:160},
            {field: 'cpzb', align: "center", sort: true, title: '差评占比',width:110},
            {field: 'hctszt', align: "center", sort: false, title: '后厨通风是否正常开启',width:180},
            {field: 'hcqmzt', align: "center", sort: false, title: '后厨墙面状态',width:120},
            {field: 'hcdmzt', align: "center", sort: false, title: '后厨地面状态',width:120},
            {field: 'hcsbzt', align: "center", sort: false, title: '后厨设备状态',width:120},
            {field: 'xwjzt', align: "center", sort: false, title: '洗碗间状态',width:100},
            {field: 'klzt', align: "center", sort: false, title: '烤炉是否正常使用',width:160},
            {field: 'bxzt', align: "center", sort: false, title: '冰箱是否无异味',width:130},
            {field: 'djjzt', align: "center", sort: false, title: '豆浆机是否无异味',width:150},
            {field: 'yyzzt', align: "center", sort: false, title: '油烟罩状态',width:100},
            {field: 'xsdzt', align: "center", sort: false, title: '下水道状态',width:100},
            {field: 'remark', align: "center", sort: false, title: '备注',width:80},
            {field: 'kylx', align: "center", sort: false, title: '烤鱼类型',width:90},
            {field: 'sfbz', align: "center", sort: false, title: '是否按照标准操作',width:160},
            {field: 'sczt', align: "center", sort: false, title: '食材是否符合标准',width:160},
            {field: 'cpzt', align: "center", sort: false, title: '成品外观是否符合标准',width:180},
            {field: 'kfhwlx', align: "center", sort: false, title: '库房货物类型',width:120},
            {field: 'tbwllx', align: "center", sort: false, title: '糖包物料类型',width:120},
            {field: 'gqhwlx', align: "center", sort: false, title: '过期货物类型',width:120},
            {field: 'sum_qjws', align: "center", sort: true, title: '清洁卫生得分',width:130},
            {field: 'sum_yryb', align: "center", sort: true, title: '仪容仪表得分',width:130},
            {field: 'sum_fwlc', align: "center", sort: true, title: '服务流程得分',width:130},
            {field: 'sum_dzdp', align: "center", sort: true, title: '大众点评得分',width:130},
            {field: 'sum_cppz', align: "center", sort: true, title: '产品品质得分',width:130},
            {field: 'sum_xq', align: "center", sort: true, title: '效期得分',width:120},
            {field: 'create_time',templet:"<div>{{layui.util.toDateString(d.create_time, 'yyyy-MM-dd')}}</div>",align: "center", sort: true, title: '创建时间',width:110},

        ]];
    };

    /**
     * 点击查询按钮
     */
    Notice.search = function () {
        var queryData = {};
        queryData['condition'] = $("#condition").val();
        queryData['timeLimit'] = $("#timeLimit").val();
        queryData['dm'] = $("#dm").val();
        table.reload(Notice.tableId, {
            where: queryData, page: {curr: 1}
        });
    };

    /**
     * 弹出添加通知
     */
    Notice.openAddNotice = function () {
        func.open({
            height: 1000,
            title: '添加巡店',
            content: Feng.ctxPath + '/btyXd/btyXd_add',
            tableId: Notice.tableId
        });
    };
    /**
     * 点击删除通知
     *
     * @param data 点击按钮时候的行数据
     */
    Notice.onDeleteNotice = function (data) {
        var operation = function () {
            var ajax = new $ax(Feng.ctxPath + "/btyXd/delete", function (data) {
                Feng.success("删除成功!");
                table.reload(Notice.tableId);
            }, function (data) {
                Feng.error("删除失败!" + data.responseJSON.message + "!");
            });
            ajax.set("id", data.id);
            ajax.start();
        };
        Feng.confirm("是否删除?", operation);
    };
    /**
     * 点击修改档案
     *
     * @param data 点击按钮时候的行数据
     */
    Notice.onEditNotice = function (data) {
        func.open({
            height: 1000,
            title: '修改巡店',
            content: Feng.ctxPath + "/btyXd/btyXd_update/" + data.id,
            tableId: Notice.tableId
        });
    };

    /**
     * 导出excel按钮
     */
    Notice.exportExcel = function () {
        //获取导出Excel的数据
        var ajax = new $ax(Feng.ctxPath + "/btyXd/listExport");
        var condition = $("#condition").val();
        var timeLimit = $("#timeLimit").val();
        var dm = $("#dm").val();
        ajax.set("condition",condition);
        ajax.set("dm",dm);
        ajax.set("timeLimit",timeLimit);
        var result = ajax.start();
        var checkRows = table.checkStatus(Notice.tableId);
        if (checkRows.data.length === 0) {
            Feng.error("请选择要导出的数据");
        } else {
            //身份证银行卡导出excel科学计数法问题
            var lists=result;
            // for(index in lists){
            //     var picture= lists[index].wwztImg;
            //     alert(picture);
            //     lists[index].wwztImg=picture+"\t";
            //     // var yhk= lists[index].yhk;
            //     // lists[index].bh= bh+"\t";
            //     // lists[index].yhk= yhk+"\t";
            //
            // }
            table.exportFile(tableResult.config.id, lists, 'xls');
        }
    };

    // 渲染表格
    var tableResult = table.render({
        elem: '#' + Notice.tableId,
        url: Feng.ctxPath + '/btyXd/list',
        page: true,
        height: "full-98",
        cellMinWidth: 100,
        cols: Notice.initColumn(),
        // done:function (res, curr, count) {
        //     //图片预览
        //     layer.photos({
        //         photos: '.show_img',
        //         anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
        //     });
        // }
    });

    // 搜索按钮点击事件
    $('#btnSearch').click(function () {
        Notice.search();
    });

    // 添加按钮点击事件
    $('#btnAdd').click(function () {
        Notice.openAddNotice();
    });
    // 导出按钮点击事件
    $('#btnExp').click(function () {
        Notice.exportExcel();
    });


    // 工具条点击事件
    table.on('tool(' + Notice.tableId + ')', function (obj) {
        var data = obj.data;
        var layEvent = obj.event;

        if (layEvent === 'edit') {
            Notice.onEditNotice(data);
        } else if (layEvent === 'delete') {
            Notice.onDeleteNotice(data);
        }
    });
});
